// pages/apply/apply.js
const app = getApp()

Page({
  data: {
    head:"../../img/a_32_03.png",
    take:"50.0",
    take_money:"",
    userName: "",
    avatarUrl: "",
    card:'',
  },
  all_take:function(e){
    let that = this;
    var take = that.data.take
    var take_money = that.data.take_money
    that.setData({
      take_money:take
    })
  },
  input_num:function(e){
    let that = this;
    var take = that.data.take
    var take_money = that.data.take_money
    if (Number(e.detail.value) > Number(take)){
      wx.showToast({
        title: '超额提现',
      })
      that.setData({
        take_money: take,
      })
    }else{
      that.setData({
        take_money: e.detail.value,
      })
    }
  },
  input_card: function (e) {
    let that = this;
    var card = that.data.card;
    var ipt_card = e.detail.value;
    that.setData({ card: ipt_card })
  },
  money_sumit : function(e){
    var that = this ;
    var take_money = that.data.take_money;
    var card = that.data.card;
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.url + '/Reback/money_request',
      method: 'post',
      data: { uid: uid, money: take_money,card :card},
      success: function (res) {
        if(res.data.code == 1){
          wx.showToast({
            title: '体现申请已经提交',
          }) 
          wx.navigateTo({
            url: '../cashback/cashback',
          })
        }
      }
    })
  },
  onLoad: function (options) {
  
  },
  onReady: function () {
  
  },
  onShow: function () {
    let that = this;
    var uid  = wx.getStorageSync('uid');
    wx.request({
      url: app.url + '/Reback/request_money',
      method: 'post',
      data: { uid: uid },
      success: function (res) {
        that.setData({
          take: res.data.data.money
        })
      }
    })
    that.setData({
      userName: app.data.userName ||"未知用户"
    })
    that.setData({
      avatarUrl: app.data.avatarUrl ||"../../img/a_50_03.png"
    })
  },
  onHide: function () {
  
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
  
  }
})